<template>
  <div>
    <Container>
      <van-form>
        <van-field
          v-model="username"
          name="手机号"
          label="手机号"
          placeholder="手机号"
          :rules="[{ required: true, message: '请填写手机号' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="密码"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin: 16px">
          <van-button round block type="info" native-type="submit" @click="onSearch">
            提交
          </van-button>
        </div>
      </van-form>
    </Container>
  </div>
</template>

<script>
import Container from "../components/container/Container"; //引入子组件（容器组件）
import {setToken} from "./../utils/storage/index.js";//引入保存本地的封装方法
import Vue from "vue";
import { Form ,Field ,Button } from "vant";

Vue.use(Form);
Vue.use(Field);
Vue.use(Button);
export default {
  components: {
    //注册组件
    Container,
  },
  data() {
      return {
          username:"",//手机号
          password:"",//密码
      }
  },
  methods: {
      onSearch(){//点击登录
        this.$APIShow.login(this.username,this.password).then(res=>{
            console.log(res.data.data.token);
            var token = res.data.data.token;//登录成功是会返回一个token
            localStorage.setItem("token",token);
            localStorage.setItem("username",this.username);
            this.$router.pushRouteByQuery("/");
        }).catch(err=>{
            console.log(err);
        })
      }
  },
};
</script>
<style lang="scss" scoped>
</style>